<html>
<head><meta charset="utf-8"><title>pretty fmt newtype struct · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html">pretty fmt newtype struct</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225934246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225934246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225934246">(Feb 11 2021 at 00:36)</a>:</h4>
<p>does anyone else imagine a utopian reality where <code>:#?</code> doesn't put newlines in newtype structs</p>



<a name="225945925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225945925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225945925">(Feb 11 2021 at 03:52)</a>:</h4>
<p>In general, I feel like <code>{:?}</code> is way too dense (no linebreaks! <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span>) and <code>{:#?}</code> is way too sparse (linebreaks everywhere! my terminal is full! <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span>).</p>



<a name="225946346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225946346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225946346">(Feb 11 2021 at 04:00)</a>:</h4>
<p>Is there enough context for the formatter to in principle do a proper job of pretty printing? I suspect it's constrained by not having any buffers</p>



<a name="225946379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225946379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225946379">(Feb 11 2021 at 04:01)</a>:</h4>
<p>proper job meaning wadler-style or similar, where you pay attention to how much space you have on the line and add newlines only if you have to</p>



<a name="225946625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225946625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225946625">(Feb 11 2021 at 04:06)</a>:</h4>
<p>I don't think so, not with the way it's currently designed. But I think we could special-case one-element tuple structs in the <code>derive</code>d impl to be on one line (if people thought that was a good idea).</p>



<a name="225950420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225950420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225950420">(Feb 11 2021 at 05:30)</a>:</h4>
<p>There's definitely not enough information to do it fully TeX boxes-and-glue properly.</p>



<a name="225950465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225950465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225950465">(Feb 11 2021 at 05:30)</a>:</h4>
<p>I'd be in favour of special-casing one-element structs, personally.</p>



<a name="225950548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225950548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225950548">(Feb 11 2021 at 05:32)</a>:</h4>
<p>There are also some hacks that might work usably -- I've been pondering that <code>dbg!</code> try to write to a 40-byte stack buffer with <code>{:?}</code>, and use that if it fit, and only use <code>{:#?}</code> if it didn't fit.  The idea being that <code>[1, 2, 3, 4]</code> and <code>("hello", 5)</code> are really not worth splitting.</p>



<a name="225952580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225952580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225952580">(Feb 11 2021 at 06:18)</a>:</h4>
<p>There are at least some formatters that are one-use only (looking at you, <a href="https://docs.rs/itertools/0.10.0/itertools/trait.Itertools.html#method.format"><code>Itertools::format</code></a>), so that strategy could cause them trouble.</p>



<a name="225952776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/225952776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#225952776">(Feb 11 2021 at 06:23)</a>:</h4>
<p>Well that's unpleasant.  Definitely not what I expect from a <code>&amp;self</code> method.</p>



<a name="226226255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/pretty%20fmt%20newtype%20struct/near/226226255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/pretty.20fmt.20newtype.20struct.html#226226255">(Feb 13 2021 at 04:35)</a>:</h4>
<p><del>Isn't it a <code>self</code> method?</del> Oh, I see: <code>Display::fmt</code> is an <code>&amp;self</code> method.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>